import {
  queryDriverList,
  deleteDriver,
  updateDriver,
  addDriver,
  organizeList
} from '@/services/api';

export default {
  namespace: 'driver',

  state: {
    driverList: [],
  },

  effects: {
    *fetchQueryDriverList({ payload, callback }, { call, put }) {
      const response = yield call(queryDriverList , payload);
      if (callback) callback(response);
      yield put({
        type: 'queryDriverList',
        payload: response,
      });
    },
    *fetchDeleteDriver({ payload, callback }, { call, put }) {
      const response = yield call(deleteDriver, payload);
      if (callback) callback(response);
    },
    *fetchAddDriver({ payload, callback }, { call, put }) {
      const response = yield call(addDriver, payload);
      if (callback) callback(response);
    },
    *fetchUpdateDriver({ payload, callback }, { call, put }) {
      const response = yield call(updateDriver, payload);
      if (callback) callback(response);
    },
    // 组织架构
    *fetchOrganize({ payload, callback }, { call, put }) {
      const response = yield call(organizeList, payload);
      if (callback) callback(response);
    },
  },

  reducers: {
    queryDriverList(state,action){
      return {
        ...state,
        driverList: action.payload
      }
    }
  },
};
